package com.pinyoumei.app.adapter;

import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.pinyoumei.app.R;
import com.pinyoumei.app.bean.HistoryPtBean;
import com.pinyoumei.app.view.SDAdaptiveTextView;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2021-08-09.
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2021-08-09        Administrator             新增Person类
 * 2021-08-09        Administrator             增加sex属性
 */
public class PTHistoryAdapter extends BaseQuickAdapter<HistoryPtBean .ResultBean.OrderListBean, BaseViewHolder> {
    private int num;
    public PTHistoryAdapter(int can_pick_num, int layoutResId, @Nullable List<HistoryPtBean.ResultBean.OrderListBean> data) {
        super(layoutResId, data);
        num = can_pick_num;
    }

    protected void convert(BaseViewHolder helper, HistoryPtBean .ResultBean.OrderListBean item) {
        helper.addOnClickListener(R.id.bt_1);
        helper.addOnClickListener(R.id.bt_2);
        helper.addOnClickListener(R.id.bt_3);

        Button bt_1 = helper.getView(R.id.bt_1);
        Button bt_2 = helper.getView(R.id.bt_2);
        Button bt_3 = helper.getView(R.id.bt_3);
        bt_1.setVisibility(View.VISIBLE);
        bt_2.setVisibility(View.VISIBLE);
        bt_3.setVisibility(View.VISIBLE);


        SDAdaptiveTextView tv_order_no = helper.getView(R.id.tv_order_no);
        tv_order_no.post(new Runnable() {
            @Override
            public void run() {
                tv_order_no.setAdaptiveText("订单编号：" + item.getOrder_no());
            }
        });

        ImageView iv_bg = helper.getView(R.id.iv_bg);
        Glide.with(mContext).load(item.getGoods_img()).into(iv_bg);

        helper.setText(R.id.tv_goods_name,item.getGoods_name());
        helper.setText(R.id.tv_goods_num,"x" +item.getGoods_num());
        helper.setText(R.id.tv_goods_price,"¥" +item.getGoods_price());


        if (!TextUtils.isEmpty(item.getOrder_time())){
            helper.setText(R.id.tv_order_time,"下单:" +item.getOrder_time());
        }
        if (!TextUtils.isEmpty(item.getApply_time())){
            helper.setText(R.id.tv_apply_time,"申请:" +item.getApply_time());
        }
        if (!TextUtils.isEmpty(item.getSpelled_time())){
            helper.setText(R.id.tv_spelled_time,"团中:" +item.getSpelled_time());
        }
        if (!TextUtils.isEmpty(item.getExchange_time())){
            helper.setText(R.id.tv_exchange_time,"转化:" +item.getExchange_time());
        }





        TextView tv_order_spell_status_desc = helper.getView(R.id.tv_order_spell_status_desc);
        tv_order_spell_status_desc.setText(item.getOrder_spell_status_desc());


        if (num>0){
            bt_1.setVisibility(View.VISIBLE);
        }else {
            bt_1.setVisibility(View.GONE);
        }

//        订单状态 3待申请 4已申请 5已转化 6转积分 示例：3
        switch (item.getOrder_spell_status()) {
        	case 3:
        	    if(num>0) {
                    bt_1.setVisibility(View.VISIBLE);
                    bt_2.setVisibility(View.VISIBLE);
                    bt_3.setVisibility(View.VISIBLE);
                }else{
                    bt_1.setVisibility(View.GONE);
                    bt_2.setVisibility(View.VISIBLE);
                    bt_3.setVisibility(View.VISIBLE);
                }
                tv_order_spell_status_desc.setTextColor(ContextCompat.getColor(mContext,R.color.text_red2));
                tv_order_spell_status_desc.setBackground(ContextCompat.getDrawable(mContext,R.drawable.shanpe_red_corner_5dp));
        		break;

            case 4:
                bt_1.setVisibility(View.GONE);
                bt_2.setVisibility(View.GONE);
                bt_3.setVisibility(View.GONE);
                tv_order_spell_status_desc.setTextColor(ContextCompat.getColor(mContext,R.color.green_bg2));
                tv_order_spell_status_desc.setBackground(ContextCompat.getDrawable(mContext,R.drawable.shanpe_green_corner_5dp));
                break;

            case 5:
            case 6:
                bt_1.setVisibility(View.GONE);
                bt_2.setVisibility(View.GONE);
                bt_3.setVisibility(View.GONE);
                tv_order_spell_status_desc.setTextColor(ContextCompat.getColor(mContext,R.color.text_gray2));
                tv_order_spell_status_desc.setBackground(ContextCompat.getDrawable(mContext,R.drawable.shanpe_gray_corner_5dp));
                break;
        	default:
        		break;
        }
    }

}
